package TreeSet;

import java.util.ArrayList;
import java.util.Iterator;

public class GenericDemo7 {
    public static void main(String[] args) {
        // 创建集合
        ArrayList<Teacher> list1=new ArrayList<Teacher>();
        //存储数据
        list1.add(new Teacher("黑旋风",18));
        list1.add(new Teacher("助教",29));
        list1.add(new Teacher("班主任",25));
        ArrayList<Student> list2=new ArrayList<Student>();
        list2.add(new Student("班长",18));
        list2.add(new Student("班花",29));
        list2.add(new Student("班草",25));
        ArrayList<Cat> list3=new ArrayList<Cat>();
        //存储数据
        list3.add(new Cat("小花",1));
        list3.add(new Cat("小黑",4));
        list3.add(new Cat("小白",2));
        /*
         * 调用自定义函数遍历上述集合
         */
        printCollection(list1);
        printCollection(list2);
    }
    public static void printCollection(ArrayList<? extends Person> list2) {
        for (Iterator<? extends Person> it = list2.iterator(); it.hasNext();) {
            System.out.println(it.next());
        }
    }
}
